package com.example.server.controller.admin;

import com.example.server.common.config.annotation.MustLogin;
import com.example.server.common.config.auth.TokenUser;
import com.example.server.common.constant.Result;
import com.example.server.service.admin.ConfigService;
import com.example.server.vo.ConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "Admin配置相关接口")
@RestController
@RequestMapping("/admin/config")
public class AdminConfigController {
    @Resource
    ConfigService configService;

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "配置列表", notes = "不分页,角色列表")
    @GetMapping("/list")
    public Result configList() {
        return new Result(configService.list());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "新增配置", notes = "新增配置")
    @PostMapping("/add")
    public Result addConfig(@RequestBody ConfigVO configVO, @ApiIgnore TokenUser tokenUser) {
        return configService.addConfig(configVO,tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "修改配置", notes = "修改配置")
    @PostMapping("/update")
    public Result updateConfig(@RequestBody ConfigVO configVO, @ApiIgnore TokenUser tokenUser) {
        return configService.updateConfig(configVO,tokenUser.getCustomerId());
    }
}
